﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Data.SqlClient;
using FileConvertPdfSystemSQLHelper;
using FileConvertPdfSystemModel;

namespace FileConvertPdfSystemDAL
{
    public class LoginUserConvertpdfQueue1
    {
        public int Add_LoginUserConverPdfQueue(LoginUserConvertpdfQueue loginuserFileQueue)
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlParameter[] ParamList ={ 
              sqlHelper.CreateInParam("@User_Id",SqlDbType.Int,4,loginuserFileQueue.User_ID),
              sqlHelper.CreateInParam("@User_Name",SqlDbType.VarChar,10,loginuserFileQueue.User_Name),
              sqlHelper.CreateInParam("@User_Score",SqlDbType.Int,4,loginuserFileQueue.User_Score),
              sqlHelper.CreateInParam("@User_Registime",SqlDbType.DateTime,8,loginuserFileQueue.User_Registime),
              sqlHelper.CreateInParam("@File_Id",SqlDbType.Int,4,loginuserFileQueue.File_ID),
              sqlHelper.CreateInParam("@File_Name",SqlDbType.NChar,50,loginuserFileQueue.File_Name),
              sqlHelper.CreateInParam("@File_UploadTime",SqlDbType.DateTime,8,loginuserFileQueue.File_UploadTime),
              sqlHelper.CreateInParam("@File_ConverSuccessful",SqlDbType.Int,4,loginuserFileQueue.FIle_ConverSuccessful)
                                      };
            try
            {
                return (sqlHelper.RunProc("ADD_LoginUserConverPdfQueue", ParamList));
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }


              


        }

        public int Update_LoginUserConverPdfQueue(LoginUserConvertpdfQueue loginuserFileQueue)
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlParameter[] ParamList ={ 
              sqlHelper.CreateInParam("@User_Id",SqlDbType.Int,4,loginuserFileQueue.ID),
              sqlHelper.CreateInParam("@User_Id",SqlDbType.Int,4,loginuserFileQueue.User_ID),
              sqlHelper.CreateInParam("@User_Name",SqlDbType.VarChar,10,loginuserFileQueue.User_Name),
              sqlHelper.CreateInParam("@User_Score",SqlDbType.Int,4,loginuserFileQueue.User_Score),
              sqlHelper.CreateInParam("@User_Registime",SqlDbType.DateTime,8,loginuserFileQueue.User_Registime),
              sqlHelper.CreateInParam("@File_Id",SqlDbType.Int,4,loginuserFileQueue.File_ID),
              sqlHelper.CreateInParam("@File_Name",SqlDbType.NChar,50,loginuserFileQueue.File_Name),
              sqlHelper.CreateInParam("@File_UploadTime",SqlDbType.DateTime,8,loginuserFileQueue.File_UploadTime),
              sqlHelper.CreateInParam("@File_ConverSuccessful",SqlDbType.Int,4,loginuserFileQueue.FIle_ConverSuccessful)
                                      };
            try
            {
                return (sqlHelper.RunProc("Update_LoginUserConverPdfQueue", ParamList));
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }





        }

        public void Delete_LoginUserConverPdfQueue(int nID)
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlParameter[] ParamList = { sqlHelper.CreateInParam("@Id", SqlDbType.Int, 4, nID) };
            try
            {
                sqlHelper.RunProc("Delete_LoginUserConverPdfQueue", ParamList);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
        }

        public List<LoginUserConvertpdfQueue> Get_LoginUserConvertpdfQueue()
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlDataReader rec = null;
            try
            {
                sqlHelper.RunProc("Get_UserInformation", out rec);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            List<LoginUserConvertpdfQueue> List_LoginUserConvertpdfQueue = new List<LoginUserConvertpdfQueue>();
            while (rec.Read())
            {
                LoginUserConvertpdfQueue LoginUserConvpdfQue = new LoginUserConvertpdfQueue();
                LoginUserConvpdfQue.ID = Int32.Parse(rec["Id"].ToString());
                LoginUserConvpdfQue.User_ID = Int32.Parse(rec["User_Id"].ToString());
                LoginUserConvpdfQue.User_Name=rec["User_Name"].ToString();
                LoginUserConvpdfQue.User_Registime=DateTime.Parse(rec["User_Registime"].ToString());
                LoginUserConvpdfQue.User_Score = Int32.Parse(rec["User_Score"].ToString());
                LoginUserConvpdfQue.File_ID=Int32.Parse(rec["File_Id"].ToString());
                LoginUserConvpdfQue.File_Name=rec["File_Name"].ToString();
                LoginUserConvpdfQue.File_UploadTime=DateTime.Parse(rec["File_UploadTime"].ToString());
                LoginUserConvpdfQue.FIle_ConverSuccessful = Int32.Parse(rec["File_ConverSuccessful"].ToString());
                List_LoginUserConvertpdfQueue.Add(LoginUserConvpdfQue);
                LoginUserConvpdfQue = null;
            }
            return List_LoginUserConvertpdfQueue;
        }

        public int Get_LoginUserConvertpdfQueueNum()
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlParameter[] ParamList = { 
                sqlHelper.CreateInParam("@User_Id",SqlDbType.Int,4,1),
                sqlHelper.CreateInParam("@File_Id",SqlDbType.Int,4,1)
            };
            SqlDataReader rec = null;
            try
            {
                sqlHelper.RunProc("Get_LoginUserConvertpdfQueueNum", ParamList, out rec);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            int Num = 0;
            while (rec.Read())
            {
                Num = Int32.Parse(rec["Counts"].ToString());
            }
            return Num;
        }

        public DataSet Get_LoginUserConvertpdfQueueRank()
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            string str = "select Id,User_Name,File_Id,File_Name,File_UploadTime from LoginUserConvertpdfQueue ORDER BY User_Score DESC";
            DataSet ds = null;
            try
            {
                sqlHelper.RunSQL(str, ref ds);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            return ds;


        }

    }
}
